<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>YUI Container - Overlay: Quickstart (YUI Library)</title>

	<link type="text/css" rel="stylesheet" href="../../../build/reset-fonts-grids/reset-fonts-grids.css">

	<link rel="stylesheet" type="text/css" href="../../../docs/assets/dpSyntaxHighlighter.css">
	<link type="text/css" rel="stylesheet" href="../assets/style.css">
</head>

<body>

	<div id="doc3" class="yui-t5">
		<div id="hd">
			<a href="http://developer.yahoo.com/yui" id="logo"><div></div></a>
			<h1>YUI Container: Overlay: Quickstart</h1>
		</div>

		<div id="bd">

					<div id="toc" class="yui-b">
			<ul>
				<li class="sect"><a href="../index.html">YUI Container: Tutorials</a></li>

<li class="item"><a href="../module/1.html">Module: Quickstart</a></li>
<li class="item selected"><a href="1.html">Overlay: Quickstart</a></li>
<li class="child active"><a href="1.html">Setting up the Overlays</a></li>
<li class="child"><a href="2.html">Functional Example</a></li>
<li class="item"><a href="../tooltip/1.html">Tooltip: Quickstart</a></li>
<li class="item"><a href="../tooltipmulti/1.html">Tooltip: One Tooltip, Many Elements</a></li>
<li class="item"><a href="../panel/1.html">Panel: Quickstart</a></li>
<li class="item"><a href="../skin/1.html">Panel: Skinning</a></li>
<li class="item"><a href="../panelskin/1.html">Panel: Advanced Skinning using CSS</a></li>
<li class="item"><a href="../panelwait/1.html">Panel: Creating a 'Loading' Popup</a></li>
<li class="item"><a href="../panelphotobox/1.html">PhotoBox: Subclassing Panel</a></li>
<li class="item"><a href="../panelresize/1.html">ResizePanel: Creating a Resizable Panel</a></li>
<li class="item"><a href="../dialog/1.html">Dialog Quickstart</a></li>
<li class="item"><a href="../simpledialog/1.html">SimpleDialog Quickstart</a></li>
<li class="item"><a href="../effect/1.html">Using ContainerEffect</a></li>
<li class="item"><a href="../overlaymanager/1.html">Using OverlayManager</a></li>
<li class="item"><a href="../keylistener/1.html">Using KeyListener</a></li>
			</ul>
		</div>
			<div id="yui-main">
				<div class="yui-b">
					<h1 class="first">Setting up the Overlays</h1>

								<p>The Overlay control is an extension of Module; its role is to facilitate the creation of modular content that is absolutely positioned above the flow of a page. It adds additional functionality to Module, including methods for positioning, multiple custom events for monitoring internal property changes, and a built-in IFRAME solution for dealing with SELECT element bleed-through in Internet Explorer.</p>

			<p>Overlay is fundamentally a building block for other UI controls. The concepts presented in this example will form the basis for the way that you interact with all of its subclasses.</p>

			<p>In this tutorial we will build three Overlays with different types of positioning. One of them will be based on existing markup; the other two will be created dynamically using script. In addition to instantiating the Overlays, we will also use the constructor to pass configuration properties for each of our Overlays.</p>

			<textarea name="code" class="JScript" cols="60" rows="1">
					// Build overlay1 based on markup, initially hidden, fixed to the center of the viewport, and 300px wide
					YAHOO.example.container.overlay1 = new YAHOO.widget.Overlay("overlay1", { fixedcenter:true,
																							  visible:false,
																							  width:"300px" } );
					YAHOO.example.container.overlay1.render();


					// Build overlay2 dynamically, initially hidden, at position x:400,y:500, and 300px wide
					YAHOO.example.container.overlay2 = new YAHOO.widget.Overlay("overlay2", { xy:[400,500],
																							  visible:false,
																							  width:"300px" } );
					YAHOO.example.container.overlay2.setHeader("Overlay #2 from Script");
					YAHOO.example.container.overlay2.setBody("This is a dynamically generated Overlay.");
					YAHOO.example.container.overlay2.setFooter("End of Overlay #2");
					YAHOO.example.container.overlay2.render(document.body);

					// Build overlay3 dynamically, initially hidden, aligned to context element "context", and 200px wide
					YAHOO.example.container.overlay3 = new YAHOO.widget.Overlay("overlay3", { context:["ctx","tl","bl"],
																							  visible:false,
																							  width:"200px" } );
					YAHOO.example.container.overlay3.setHeader("Overlay #3 from Script");
					YAHOO.example.container.overlay3.setBody("This is a dynamically generated Overlay.");
					YAHOO.example.container.overlay3.setFooter("End of Overlay #3");
					YAHOO.example.container.overlay3.render(document.body);

					YAHOO.util.Event.addListener("show1", "click", YAHOO.example.container.overlay1.show, YAHOO.example.container.overlay1, true);
					YAHOO.util.Event.addListener("hide1", "click", YAHOO.example.container.overlay1.hide, YAHOO.example.container.overlay1, true);

					YAHOO.util.Event.addListener("show2", "click", YAHOO.example.container.overlay2.show, YAHOO.example.container.overlay2, true);
					YAHOO.util.Event.addListener("hide2", "click", YAHOO.example.container.overlay2.hide, YAHOO.example.container.overlay2, true);

					YAHOO.util.Event.addListener("show3", "click", YAHOO.example.container.overlay3.show, YAHOO.example.container.overlay3, true);
					YAHOO.util.Event.addListener("hide3", "click", YAHOO.example.container.overlay3.hide, YAHOO.example.container.overlay3, true);
			</textarea>

			<p>These Overlays introduce a few configuration properties. The "fixedcenter" property, when set to true, will force the Overlay to always be positioned in the center of the viewport &mdash; even when the window is scrolled or resized. The "visible" property determines whether the Overlay should be visible, and the "width" property allows a CSS width to be set for the Overlay. In addition, basic pixel-based positioning is available via the "xy" property, which can also be split into separate properties ("x" and "y").</p>

			<p>The "context" property, as shown in "overlay3", takes an array of arguments. The first argument in the array is the id of the element to which we want to anchor the Overlay. In this case, that element is a div with an id of "ctx". The next two arguments specify the positioning of the Overlay &mdash; "tl" and "bl" mean, "Anchor my Overlay's <em>t</em>op <em>l</em>eft corner to my context element's <em>b</em>ottom <em>l</em>eft corner." (Other possible values include "tr" and "br" for "top right" and "bottom right", respectively.)</p>

			<p>In the next step, we will define CSS styles that allow us to see a clear visual representation of our Overlays; remember, Overlays are building blocks for other controls and as such they are not styled by default. We will also style our "ctx" context element so that it's easy to see:</p>

			<textarea name="code" class="HTML" cols="60" rows="1">
				<style>
					.yui-overlay { border:1px dotted black;padding:5px;margin:10px; }
					.yui-overlay .hd { border:1px solid red;padding:5px; }
					.yui-overlay .bd { border:1px solid green;padding:5px; }
					.yui overlay .ft { border:1px solid blue;padding:5px; }

					#ctx { background:orange;width:100px;height:25px; }
				</style>
			</textarea>

			<p>The markup for "overlay1", plus the context element "ctx" and the buttons to show all our Overlays, is displayed below. Note that "overlay1" has an inline style of "visibility:hidden" set in advance. Most browsers are slower to render CSS than inline styles, and we want this marked-up Overlay to be hidden by default. If the inline style isn't present, it may cause a brief "flash of unstyled content" where the Overlay may be visible on slower machines.</p>

			<textarea name="code" class="HTML" cols="60" rows="1">
				<div>
					overlay1:
					<button id="show1">Show</button>
					<button id="hide1">Hide</button>
				</div>
				<div>
					overlay2:
					<button id="show2">Show</button>
					<button id="hide2">Hide</button>
				</div>
				<div>
					overlay3:
					<button id="show3">Show</button>
					<button id="hide3">Hide</button>
				</div>

				<div id="ctx">Align to me</div>

				<div id="overlay1" style="visibility:hidden">
					<div class="hd">Overlay #1 from Markup</div>
					<div class="bd">This is a Overlay that was marked up in the document.</div>
					<div class="ft">End of Overlay #1</div>
				</div>
			</textarea>
					<div id="stepnav">
						<a class="next" href="2.html">Continue to <em>Functional Example</em> &gt;</a>					</div>
				</div>
			</div>

		</div>

		<div id="ft">&nbsp;</div>
	</div>

	<script src="../../../docs/assets/dpSyntaxHighlighter.js"></script>
	<script language="javascript">
		dp.SyntaxHighlighter.HighlightAll('code');
	</script>

</body>
</html>